﻿
var columns =
            [
                 { display: 'Key', name: 'Key', type: 'text', hide: 1 },
                { display: '登陆名', name: 'LoginName', mintWidth: 80, width: 120 }, //, type: 'int', mintWidth: 40, width: 100
                {display: '姓名', name: 'Name', mintWidth: 80, width: 120 },
                { display: '性别', name: 'Gender', mintWidth: 60, width: 80 },
                { display: '出生年月', name: 'Birthday', type: 'selfDate', width: 140 },
                { display: '移动电话', name: 'Mobile', mintWidth: 80, width: 140 },
                { display: '固定电话', name: 'Tel', mintWidth: 80, width: 140 },
                { display: 'QQ', name: 'QQ', mintWidth: 80, width: 120 },
                { display: '组织机构', name: 'OrgName', mintWidth: 80, width: 120 },
                { display: '部门', name: 'DeptName', mintWidth: 80, width: 120 },
                { display: '状态', name: 'IsEnable', mintWidth: 80, width: 120 }
             ];

var manager;
//init controls
$(document).ready(function () {
    $("#btnSearch").unbind("click").bind("click", initligerGrid);
    initligerGrid();
});

function initligerGrid() {
    manager = null;
    manager = $("#usersGrid").ligerGrid({
        columns: columns,
        title: '用户管理',
        showTitle: true,
        width: '100%',
        enabledSort: true,
        height: '99%',
        checkbox: false,
        rownumbers: true,
        toolbar: { items: [
                                   
                                    { text: '增加', click: dialogAdd, icon: 'add' },
                                    { line: true },
                                    { text: '修改', click: modifyOperation, img: '../Content/images/edit2.png' },
                                    { line: true },
                                     { text: '禁用', click: disableOperation, icon: 'modify' },
                                    { line: true },
                                     { text: '启用', click: enableOperation, icon: 'modify' },
                                    { line: true },
                                    { text: '删除', click: deleteOperation, img: '../Content/images/delete.gif' },
                                     { line: true },
                                    { text: '查看', click: dialogDetailView, img: '../Content/images/Search.png' }
                                    ]
        },
        parms: { orgCode: $("#HidOrgCode").val(), userName: $("#userName").val(), orgName: $("#orgName").val(), deptName: $("#deptName").val(), isEnable: ($("#isEnabled").attr("checked") == true ? 0 : 1) },
        url: "../User/GetAllUserList?id=" + Math.random()
       // onDblClickRow: function (data, rowindex, rowobj) { dialogView(data.Key); }
    });
}

//detail
function dialogDetailView() {
    var row = manager.getSelectedRow();
    if (!row) { $.ligerDialog.success('请选择要查看的行!'); return; }
    var billId = row["Key"].toString();
    dialogView(billId);
}
function dialogView(billId) {
    $.ligerDialog.open({ url: "../User/UserDetail?id=" + billId, height: getDialogHeight(), width: getDialogWidth(), isResize: true, isHidden: false });
}
//add
function dialogAdd() {
    $.ligerDialog.open({ url: '../User/Add', height: getDialogHeight(), width: getDialogWidth(), 
    isResize: true, isHidden: false
    });
}

//delete
function deleteOperation() {
    var row = manager.getSelectedRow();
    if (!row) { $.ligerDialog.success('请选择需要删除行！'); return; }
    $.ligerDialog.confirm('确定要删除吗？', function (yes) {
        if (yes) {
            $.get("../User/Delete?userId=" + row["Key"].toString(), {}, function (data) {
                if (data != undefined && data == "ok") {
                    initligerGrid();
                }
            });
        }
    });
}
//update 
function modifyOperation() {
    var row = manager.getSelectedRow();
    if (!row) {
        $.ligerDialog.success('请选择要编辑的行!'); return;
    }
    $.ligerDialog.open({ url: '../User/Edit?userId=' + row["Key"].toString(), height: getDialogHeight(), width: getDialogWidth(), isResize: true, isHidden: false
    });
}

//disableOperation 
function disableOperation() {
    var row = manager.getSelectedRow();
    if (!row) { $.ligerDialog.success('请选择需要禁用行！'); return; }
    $.ligerDialog.confirm('确定要禁用吗？', function (yes) {
        if (yes) {
            $.get("../User/DisableUser?isEnable=false&userId=" + row["Key"].toString(), {}, function (data) {
                if (data != undefined && data == "ok") {
                    initligerGrid();
                }
            });
        }
    });
}
//enableOperation 
function enableOperation() {
    var row = manager.getSelectedRow();
    if (!row) { $.ligerDialog.success('请选择需要启用行！'); return; }
    $.ligerDialog.confirm('确定要启用吗？', function (yes) {
        if (yes) {
            $.get("../User/DisableUser?isEnable=true&userId=" + row["Key"].toString(), {}, function (data) {
                if (data != undefined && data == "ok") {
                    initligerGrid();
                }
            });
        }
    });
}